package com.dykj.fireFighting.server.base.government.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dykj.fireFighting.api.base.fireEngine.entity.FireEngine;
import com.dykj.fireFighting.api.base.government.entity.GovListView;
import com.dykj.fireFighting.api.base.government.entity.GovernmentProjectView;
import com.dykj.fireFighting.api.base.government.service.IGovernmentProjectViewService;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.server.base.fireEngine.mapper.FireEngineMapper;
import com.dykj.fireFighting.server.base.government.mapper.GovernmentProjectViewMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service("GovernmentProjectViewServiceImpl")
@DubboService
@Transactional(rollbackFor = Exception.class)
public class GovernmentProjectViewServiceImpl extends ServiceImpl<GovernmentProjectViewMapper, GovernmentProjectView>  implements IGovernmentProjectViewService {
    @Override
    public PageInfo<GovernmentProjectView> getPageList(String pName, String beginTime, String endTime, int page , int limit) {
        QueryWrapper queryWrapper=new QueryWrapper();
        if(StringUtils.isNotBlank(pName)){
            queryWrapper.like("p_name",pName);
        }
        if(StringUtils.isNotBlank(beginTime)){
            queryWrapper.ge("begin_time",beginTime);
        }
        if(StringUtils.isNotBlank(endTime)){
            queryWrapper.le("end_time",endTime);
        }
        queryWrapper.orderByDesc("create_time");
        PageHelper.startPage(page,limit);

        return new PageInfo<GovernmentProjectView>(this.baseMapper.selectList(queryWrapper));
    }

    @Override
    public GovernmentProjectView getLast() {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.orderByDesc("create_time");
        queryWrapper.last("limit 1");
       return getOne(queryWrapper);
    }
}
